<%#
Copyright 2013-2020 the original author or authors from the JHipster project.

This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
## How to use JHCC docker compose
# To allow JHCC to reach JHipster application from a docker container note that we set the host as host.docker.internal
# To reach the application from a browser, you need to add '127.0.0.1 host.docker.internal' to your hosts file.
### Discovery mode
# JHCC support 3 kinds of discovery mode: Consul, Eureka and static
# In order to use one, please set SPRING_PROFILES_ACTIVE to one (and only one) of this values: consul,eureka,static
### Discovery properties
# According to the discovery mode choose as Spring profile, you have to set the right properties
# please note that current properties are set to run JHCC with default values, personalize them if needed
# and remove those from other modes. You can only have one mode active.
#### Eureka
#       - EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:admin@host.docker.internal:8761/eureka/
#### Consul
#       - SPRING_CLOUD_CONSUL_HOST=host.docker.internal
#       - SPRING_CLOUD_CONSUL_PORT=8500
#### Static
# Add instances to "MyApp"
#       - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_MYAPP_0_URI=http://host.docker.internal:8081
#       - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_MYAPP_1_URI=http://host.docker.internal:8082
# Or add a new application named MyNewApp
#       - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_MYNEWAPP_0_URI=http://host.docker.internal:8080
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
<%_ let discoveryProfile = serviceDiscoveryType ? serviceDiscoveryType : 'static'; _%>
version: '<%= DOCKER_COMPOSE_FORMAT_VERSION %>'
services:
  jhipster-control-center:
    image: '<%= DOCKER_JHIPSTER_CONTROL_CENTER %>'
    command:
      - /bin/sh
      - -c
      # Patch /etc/hosts to support resolving host.docker.internal to the internal IP address used by the host in all OSes
      - echo "`ip route | grep default | cut -d ' ' -f3` host.docker.internal" | tee -a /etc/hosts > /dev/null && java -jar /jhipster-control-center.jar
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      # TODO change 'swagger' to 'api-docs' when JHCC will be migrated to 7.x JHipster version. https://github.com/jhipster/jhipster/pull/764
      - SPRING_PROFILES_ACTIVE=prod,swagger,<%= discoveryProfile %><% if (authenticationType === 'oauth2') { %>,oauth2<% } %>
      - JHIPSTER_SLEEP=30 # gives time for other services to boot before the application
      <%_ if (authenticationType === 'jwt') { _%>
      - SPRING_SECURITY_USER_PASSWORD=admin
      - JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET=<%= jwtSecretKey %>
      <%_ } else if (authenticationType === 'oauth2') { _%>
      # For keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-control-center
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-control-center
      <%_ } _%>
      <%_ if (discoveryProfile === 'eureka') { _%>
      - EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:admin@host.docker.internal:8761/eureka/
      <%_ } else if (discoveryProfile === 'consul') { _%>
      - SPRING_CLOUD_CONSUL_HOST=host.docker.internal
      - SPRING_CLOUD_CONSUL_PORT=8500
      <%_ } else { _%>
      - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_<%= baseName.toUpperCase() %>_0_URI=http://host.docker.internal:<%= serverPort %>
      <%_ } _%>
    # If you want to expose these ports outside your dev PC, 
    # remove the "127.0.0.1:" prefix
    ports:
      - 127.0.0.1:7419:7419
